home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WINER.ZIP / CHAP11-5.BAS < prev    next >
BASIC Source File  |  1992-05-13  |  1KB  |  41 lines

  1. '*********** CHAP11-5.BAS - demonstrates testing for a valid drive
  2.  
  3. 'Copyright (c) 1992 Ethan Winer
  4.  
  5. DEFINT A-Z
  6. DECLARE SUB ChDrive (Drive$)
  7.  
  8. '$INCLUDE: 'REGTYPE.BI'
  9.  
  10. DIM SHARED Registers AS RegType
  11.  
  12. DEF FnGetDrive%
  13.   Registers.AX = &H1900
  14.   CALL Interrupt(&H21, Registers, Registers)
  15.   FnGetDrive% = (Registers.AX AND &HFF) + 65
  16. END DEF
  17.  
  18. DEF FnDriveValid% (TestDrive$)
  19.   STATIC Current                'local to this function
  20.   Current = FnGetDrive%         'save the current drive
  21.   FnDriveValid% = 0             'assume not valid
  22.   CALL ChDrive(TestDrive$)      'try to set a new drive
  23.   IF ASC(UCASE$(TestDrive$)) = FnGetDrive% THEN
  24.      FnDriveValid% = -1         'they match so it's valid
  25.   END IF
  26.   CALL ChDrive(CHR$(Current))   'either way restore it
  27. END DEF
  28.  
  29. INPUT "Enter the drive to test for validity: ", Drive$
  30. IF FnDriveValid%(Drive$) THEN
  31.    PRINT Drive$; " is a valid drive."
  32. ELSE
  33.    PRINT "Sorry, drive "; Drive$; " is not valid."
  34. END IF
  35.  
  36. SUB ChDrive (Drive$) STATIC
  37.   Registers.AX = &HE00
  38.   Registers.DX = ASC(UCASE$(Drive$)) - 65
  39.   CALL Interrupt(&H21, Registers, Registers)
  40. END SUB
  41.